// import CryptoJS from "../../node_modules/crypto-js/crypto-js.js"; //一般npm以后都是这个位置
function formatTime(num) { //时间戳数据处理
	let date = new Date(parseInt(num));
	//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	let y = date.getFullYear();
	let MM = date.getMonth() + 1;
	MM = MM < 10 ? ('0' + MM) : MM; //月补0
	let d = date.getDate();
	d = d < 10 ? ('0' + d) : d; //天补0
	let h = date.getHours();
	h = h < 10 ? ('0' + h) : h; //小时补0
	let m = date.getMinutes();
	m = m < 10 ? ('0' + m) : m; //分钟补0
	let s = date.getSeconds();
	s = s < 10 ? ('0' + s) : s; //秒补0
	return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
}

function convertDateFromString(dateStr) {
	if (dateStr) {
		dateStr = dateStr.substring(0, 19);
		dateStr = dateStr.replace(/-/g, '/');
		var date = new Date(dateStr).getTime();
		return date;
	}
}

//校验手机格式
function checkMobile(mobile) {
	return RegExp(/^(?:(?:\+|00)86)?1[3-9]\d{9}$/).test(mobile);
	// /^1[3|4|5|7|8|9][0-9]\d{8}$/
	// ^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57]|19[0-9]|16[0-9])[0-9]{8}$
}
//校验身份证
function checkIdcard(idcard) {
	return RegExp(
			/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/)
		.test(idcard);
}
// /*aes加密*/
// function setAES(keyString, ivString, str) {
// 	keyString = 'zefu20220324java';
// 	while (str.length % 16 > 0) {
// 		str += " ";
// 	}
// 	while (keyString.length % 16 > 0) {
// 		keyString += " ";
// 	}
// 	let key = CryptoJS.enc.Utf8.parse(keyString); // 秘钥
// 	let iv = CryptoJS.enc.Utf8.parse(ivString); //向量iv
// 	let encrypted = CryptoJS.AES.encrypt(str, key, {
// 		iv: iv,
// 		mode: CryptoJS.mode.CBC,
// 		padding: CryptoJS.pad.NoPadding
// 	});
// 	return encrypted.toString();
// }
// /*aes解密*/
// function decryptAES(keyString, ivString, str) {
// 	keyString = 'zefu20220324java';
// 	while (keyString.length % 16 > 0) {
// 		keyString += " ";
// 	}
// 	let key = CryptoJS.enc.Utf8.parse(keyString); // 秘钥
// 	let iv = CryptoJS.enc.Utf8.parse(ivString); //向量iv
// 	let decryptedData = CryptoJS.AES.decrypt(str, key, {
// 		iv: iv,
// 		mode: CryptoJS.mode.CBC,
// 		padding: CryptoJS.pad.NoPadding
// 	});
// 	var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);
// 	return decryptedStr;
// }
module.exports = {
	convertDateFromString: convertDateFromString,
	formatTime: formatTime,
	checkMobile: checkMobile,
	checkIdcard: checkIdcard
	// setAES,
	// decryptAES
}